Public Class Matrix4Ddouble
    Implements IDisposable
    Public i, j, k, l As Integer
    Public data(,,,) As Double
    Public Sub Replace(ByVal what As Double, ByVal bywhat As Double)
        Dim a, b, c, d As Integer
        For a = 0 To i - 1
            For b = 0 To j - 1
                For c = 0 To k - 1
                    For d = 0 To l - 1
                        If data(a, b, c, d) = what Then data(a, b, c, d) = bywhat
                    Next
                Next
            Next
        Next
    End Sub
    Public Sub New()
        ReDim data(0, 0, 0, 0)
        i = 1
        j = 1
        k = 1
        l = 1
    End Sub
    Public Sub New(ByVal i As Integer, ByVal j As Integer, ByVal k As Integer, ByVal l As Integer)
        Me.i = i
        Me.j = j
        Me.k = k
        Me.l = l
        ReDim Me.data(i - 1, j - 1, k - 1, l - 1)
        'automatically assigned 
    End Sub
    Public Sub New(ByVal data(,,,) As Double, ByVal i As Integer, ByVal j As Integer, ByVal k As Integer, ByVal l As Integer)
        Me.data = data
        Me.i = i
        Me.j = j
        Me.k = k
        Me.l = l
    End Sub

    Public Sub New(ByVal dataa(,,,) As Int16, ByVal i As Integer, ByVal j As Integer, ByVal k As Integer, ByVal l As Integer)
        Me.i = i
        Me.j = j
        Me.k = k
        Me.l = l
        ReDim Me.data(i - 1, j - 1, k - 1, l - 1)
        'automatically assigned 
        Dim a, b, c, d As Integer
        For a = 0 To i - 1
            For b = 0 To j - 1
                For c = 0 To k - 1
                    For d = 0 To l - 1
                        Me.data(a, b, c, d) = Convert.ToDouble(dataa(i, j, k, l))
                    Next
                Next
            Next
        Next
    End Sub

    Public Function Log(ByVal base10 As Boolean) As Double(,,,)
        Dim temp(i, j, k, l) As Double
        Dim a, b, c, d As Integer
        For a = 0 To i - 1
            For b = 0 To j - 1
                For c = 0 To k - 1
                    For d = 0 To l - 1
                        If base10 = False Then
                            temp(a, b, c, d) = Math.Log(data(a, b, c, d))
                        Else
                            temp(a, b, c, d) = Math.Log10(data(a, b, c, d))
                        End If
                    Next
                Next
            Next
        Next
        Return temp
    End Function

    Public Sub SubtractFromEachVolume(ByVal data As Double(,,), ByVal VolumeNo As Integer)
        Dim a, b, c As Integer
        For a = 0 To i - 1
            For b = 0 To j - 1
                For c = 0 To k - 1
                    Me.data(a, b, c, VolumeNo) -= data(a, b, c)
                Next
            Next
        Next
    End Sub

    Public Function ExtractVolume(ByVal VolumeNo As Integer) As Double(,,)
        Dim temp(i, j, k) As Double
        Dim a, b, c As Integer
        For a = 0 To i - 1
            For b = 0 To j - 1
                For c = 0 To k - 1
                    temp(a, b, c) = Me.data(a, b, c, VolumeNo)
                Next
            Next
        Next
        Return temp
    End Function
    Public Sub LoadVolume(ByVal VolumeNo As Integer, ByVal MatrixData As Double(,,))
        Dim a, b, c As Integer
        For a = 0 To i - 1
            For b = 0 To j - 1
                For c = 0 To k - 1
                    data(a, b, c, VolumeNo) = MatrixData(a, b, c)
                Next
            Next
        Next
    End Sub
    Private Disposed As Boolean = False
    Private Overloads Sub Dispose(ByVal disposing As Boolean)
        ' Check to see if Dispose has already been called.
        If Not Me.disposed Then
            ' If disposing equals true, dispose all managed 
            ' and unmanaged resources.
            If disposing Then
                ' Dispose managed resources.
                i = Nothing
                j = Nothing
                k = Nothing
                l = Nothing
                data = Nothing
            End If

            ' Call the appropriate methods to clean up 
            ' unmanaged resources here.
            ' If disposing is false, 
            ' only the following code is executed.
        End If
        disposed = True
    End Sub
    ' Implement IDisposable.
    ' Do not make this method virtual.
    ' A derived class should not be able to override this method.
    Public Overloads Sub Dispose() Implements IDisposable.Dispose
        Dispose(True)
        ' This object will be cleaned up by the Dispose method.
        ' Therefore, you should call GC.SupressFinalize to
        ' take this object off the finalization queue 
        ' and prevent finalization code for this object
        ' from executing a second time.
        GC.SuppressFinalize(Me)
    End Sub
End Class
Public Class Matrix4DdoubleS
    Implements IDisposable
    Public i, j, k, l As Integer
    Public data(,,,) As Single
    Public Sub Replace(ByVal what As Double, ByVal bywhat As Double)
        Dim a, b, c, d As Integer
        For a = 0 To i - 1
            For b = 0 To j - 1
                For c = 0 To k - 1
                    For d = 0 To l - 1
                        If data(a, b, c, d) = what Then data(a, b, c, d) = bywhat
                    Next
                Next
            Next
        Next
    End Sub
    Public Sub New()
        ReDim data(0, 0, 0, 0)
        i = 1
        j = 1
        k = 1
        l = 1
    End Sub
    Public Sub New(ByVal i As Integer, ByVal j As Integer, ByVal k As Integer, ByVal l As Integer)
        Me.i = i
        Me.j = j
        Me.k = k
        Me.l = l
        ReDim Me.data(i - 1, j - 1, k - 1, l - 1)
        'automatically assigned 
    End Sub
    Public Sub New(ByVal data(,,,) As Single, ByVal i As Integer, ByVal j As Integer, ByVal k As Integer, ByVal l As Integer)
        Me.data = data
        Me.i = i
        Me.j = j
        Me.k = k
        Me.l = l
    End Sub

    Public Sub New(ByVal dataa(,,,) As Int16, ByVal i As Integer, ByVal j As Integer, ByVal k As Integer, ByVal l As Integer)
        Me.i = i
        Me.j = j
        Me.k = k
        Me.l = l
        ReDim Me.data(i - 1, j - 1, k - 1, l - 1)
        'automatically assigned 
        Dim a, b, c, d As Integer
        For a = 0 To i - 1
            For b = 0 To j - 1
                For c = 0 To k - 1
                    For d = 0 To l - 1
                        Me.data(a, b, c, d) = Convert.ToDouble(dataa(i, j, k, l))
                    Next
                Next
            Next
        Next
    End Sub

    Public Function Log(ByVal base10 As Boolean) As Double(,,,)
        Dim temp(i, j, k, l) As Double
        Dim a, b, c, d As Integer
        For a = 0 To i - 1
            For b = 0 To j - 1
                For c = 0 To k - 1
                    For d = 0 To l - 1
                        If base10 = False Then
                            temp(a, b, c, d) = Math.Log(data(a, b, c, d))
                        Else
                            temp(a, b, c, d) = Math.Log10(data(a, b, c, d))
                        End If
                    Next
                Next
            Next
        Next
        Return temp
    End Function

    Public Sub SubtractFromEachVolume(ByVal data As Double(,,), ByVal VolumeNo As Integer)
        Dim a, b, c As Integer
        For a = 0 To i - 1
            For b = 0 To j - 1
                For c = 0 To k - 1
                    Me.data(a, b, c, VolumeNo) -= data(a, b, c)
                Next
            Next
        Next
    End Sub

    Public Function ExtractVolume(ByVal VolumeNo As Integer) As Double(,,)
        Dim temp(i, j, k) As Double
        Dim a, b, c As Integer
        For a = 0 To i - 1
            For b = 0 To j - 1
                For c = 0 To k - 1
                    temp(a, b, c) = Me.data(a, b, c, VolumeNo)
                Next
            Next
        Next
        Return temp
    End Function
    Public Sub LoadVolume(ByVal VolumeNo As Integer, ByVal MatrixData As Double(,,))
        Dim a, b, c As Integer
        For a = 0 To i - 1
            For b = 0 To j - 1
                For c = 0 To k - 1
                    data(a, b, c, VolumeNo) = MatrixData(a, b, c)
                Next
            Next
        Next
    End Sub
    Private Disposed As Boolean = False
    Private Overloads Sub Dispose(ByVal disposing As Boolean)
        ' Check to see if Dispose has already been called.
        If Not Me.disposed Then
            ' If disposing equals true, dispose all managed 
            ' and unmanaged resources.
            If disposing Then
                ' Dispose managed resources.
                i = Nothing
                j = Nothing
                k = Nothing
                l = Nothing
                data = Nothing
            End If

            ' Call the appropriate methods to clean up 
            ' unmanaged resources here.
            ' If disposing is false, 
            ' only the following code is executed.
        End If
        disposed = True
    End Sub
    ' Implement IDisposable.
    ' Do not make this method virtual.
    ' A derived class should not be able to override this method.
    Public Overloads Sub Dispose() Implements IDisposable.Dispose
        Dispose(True)
        ' This object will be cleaned up by the Dispose method.
        ' Therefore, you should call GC.SupressFinalize to
        ' take this object off the finalization queue 
        ' and prevent finalization code for this object
        ' from executing a second time.
        GC.SuppressFinalize(Me)
    End Sub
End Class